// split_time 
class TimeObject {
    "year": any;
    "month": any;
    "date": any;
    "hour": any;
    "min": any;
    "second": any;
};

function split_time(time_str: string): TimeObject {
    let times = time_str.split('_');
    let d = new TimeObject();
    d.year = Number(times[0] || 0);
    d.month = Number(times[1] || 0);
    d.date = Number(times[2] || 0);
    d.hour = Number(times[3] || 0);
    d.min = Number(times[4] || 0);
    d.second = Number(times[5] || 0);
    return d;
}

// load time str
function get_time_obj(time_str: string): Date {
    let t = split_time(time_str);
    let d = new Date(t.year, t.month - 1, t.date, t.hour, t.min, t.second);
    return d;
}

function get_format_date_str(date: any) {
    let d = date || new Date();
    let l = [
        d.getFullYear(), d.getMonth() + 1, d.getDate(),
        d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()
    ];
    return l.join("_");
}

exports.get_format_date_str = get_format_date_str;

function get_readable_date(time_str: string) {
    // "2022_4_4_19_11_36_270"
    let t = split_time(time_str);
    return t.year + "年" + t.month + "月" + t.date + "日" + t.hour + "时" + t.min + "分" + t.second + "秒";
}

exports.get_readable_date = get_readable_date;


exports.get_readable_end_date = function get_readable_end_date(start_time: string, duration: string) {
    let d = get_time_obj(start_time);
    let end_d = new Date(d.setMinutes(d.getMinutes() + Number(duration)));
    return get_readable_date(get_format_date_str(end_d));
}